package comdemo.controller;


import comdemo.pojo.Fitness;
import comdemo.pojo.Result;
import comdemo.service.IFitnessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 健身器材表 前端控制器
 * </p>
 *
 * @author 沈仁聪
 * @since 2025-08-19
 */
@RestController
@RequestMapping("/fitness")
public class FitnessController {

    @Autowired
    private IFitnessService fitnessService;

    /**
     * <p>
     * 获取所有健身器材的信息
     * </p>
     *
     * @author 沈仁聪
     * @since 2025-08-19
     */

    @GetMapping
    public Result getFitness()
    {
        List<Fitness> list = fitnessService.list();
        return Result.success(list);
    }

    /**
     * <p>
     * 添加健身器材的信息
     * </p>
     *
     * @author 沈仁聪
     * @since 2025-08-20
     */
    @PostMapping("/add")
    public Result addFitness(@RequestBody Fitness fitness) {
        fitnessService.save(fitness);
        return Result.success();
    }

    /**
     * <p>
     * 修改健身器材的信息
     * </p>
     *
     * @author 沈仁聪
     * @since 2025-08-20
     */
    @PostMapping("/update")
    public Result updateFitness(@RequestBody Fitness fitness) {
        fitnessService.updateById(fitness);
        return Result.success();
    }

    /**
     * <p>
     * 删除健身器材的信息
     * </p>
     *
     * @author 沈仁聪
     * @since 2025-08-20
     */
    @DeleteMapping("/delete")
    public Result deleteFitness(@RequestBody Fitness fitness) {
        fitnessService.removeById(fitness);
        return Result.success();
    }

}
